/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:55 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class XeploaichungchiDAL : SqlProvider<XeploaichungchiEntity>
    {
        static XeploaichungchiDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                XeploaichungchiEntity entity = new XeploaichungchiEntity();
				entity.FK_iChungchiID = Int16.Parse("0"+dr["FK_iChungchiID"].ToString());
				entity.iSothutu = Int16.Parse("0"+dr["iSothutu"].ToString());
				entity.iSodiem = Int16.Parse("0"+dr["iSodiem"].ToString());
				entity.sTenxeploai = dr["sTenxeploai"].ToString();
                return entity;
            };
        }
        public static XeploaichungchiEntity GetOne(Int16 FK_iChungchiID)
        {
            string cmdName = "spXeploaichungchi_GetByPK";
            SqlParameter p = new SqlParameter("@FK_iChungchiID", FK_iChungchiID);
            XeploaichungchiEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<XeploaichungchiEntity> GetAll()
        {
            string cmdName = "spXeploaichungchi_Get";
            return GetList(cmdName);
        }
        
        public static int Add(XeploaichungchiEntity entity)
        {
            string cmdName = "spXeploaichungchi_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(XeploaichungchiEntity entity)
        {
            string cmdName = "spXeploaichungchi_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int16 FK_iChungchiID)
        {
            string cmdName = "spXeploaichungchi_Delete";
            SqlParameter p = new SqlParameter("@FK_iChungchiID", FK_iChungchiID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(XeploaichungchiEntity entity)
        {
            SqlParameter[] p = new SqlParameter[4];
			p[0] = new SqlParameter("@FK_iChungchiID", entity.FK_iChungchiID);
			p[1] = new SqlParameter("@iSothutu", entity.iSothutu);
			p[2] = new SqlParameter("@iSodiem", entity.iSodiem);
			p[3] = new SqlParameter("@sTenxeploai", entity.sTenxeploai);
            return p;
        }
        #endregion
       
    }
}